import Vue from "vue";
import axios from "./router/axios";
import VueAxios from "vue-axios";
import App from "./App";
import router from "./router/router";
import "./permission"; // 权限
import "./error"; // 日志
import "./cache"; //页面缓存
import store from "./store";
import { loadStyle } from "./util/util";
import * as urls from "@/config/env";
import Element from "element-ui";
import { iconfontUrl, iconfontVersion } from "@/config/env";
import i18n from "./lang"; // Internationalization
import "./styles/common.scss";
import "./styles/icon.scss";
import basicBlock from "./components/basic-block/main";
import basicContainer from "./components/basic-container/main";
import thirdRegister from "./components/third-register/main";
import avueUeditor from "avue-plugin-ueditor";
import website from "@/config/website";
import crudCommon from "@/mixins/crud";
// 业务组件
import tenantPackage from "./views/system/tenantpackage";

// 注册全局crud驱动
window.$crudCommon = crudCommon;

import uploader from "vue-simple-uploader";
Vue.use(uploader);
// 加载Vue拓展
Vue.use(router);
Vue.use(VueAxios, axios);
Vue.use(Element, {
  i18n: (key, value) => i18n.t(key, value),
});
Vue.use(window.AVUE, {
  size: "small",
  tableSize: "small",
  calcHeight: 65,
  i18n: (key, value) => i18n.t(key, value),
});
// 注册全局容器
Vue.component("basicContainer", basicContainer);
Vue.component("basicBlock", basicBlock);
Vue.component("thirdRegister", thirdRegister);
Vue.component("avueUeditor", avueUeditor);
Vue.component("tenantPackage", tenantPackage);


import wangEditor from "./components/wang-editor/main";
Vue.component("wangEditor", wangEditor);

// 加载相关url地址
Object.keys(urls).forEach((key) => {
  Vue.prototype[key] = urls[key];
});
// 加载NutFlow
Vue.use(window.WfDesignBase);
// 加载website
Vue.prototype.website = website;
// 动态加载阿里云字体库
iconfontVersion.forEach((ele) => {
  loadStyle(iconfontUrl.replace("$key", ele));
});

import * as echarts from "echarts";
Vue.prototype.$echarts = echarts;

Vue.config.productionTip = false;

new Vue({
  router,
  store,
  i18n,
  render: (h) => h(App),
}).$mount("#app");





Vue.prototype.formValidate = function (formName='form') {
  return new Promise((resolve,reject) => {
    this.$refs[formName].validate((valid,done) => {
      if (valid) {
        resolve(done)
      }else {
        reject(done);
      }
    });
  })
};



Vue.prototype.linkConfirm = function (title) {
  return new Promise((resolve) => {
    this.$confirm(title, "提示", {
      cancelButtonText: "取消",
      confirmButtonText: "确定",
      type: "warning",
    }).then(() => {
      resolve();
    });
  })
};


Vue.prototype.message = function (data,title='操作成功') {
  if (data.code===200){
    this.$message.success(title)
  }else {
    this.$message.error(data.msg)
  }
};


Vue.prototype.message = function (data,title='操作成功') {
  return new Promise((resolve) => {
    if (data.code===200){
      this.$message.success(title)
      resolve()
    }else {
      this.$message.error(data.msg)
    }
  })
};





Vue.filter("replacestar", function (value) {
  if (!value) return "";
  let str = value;
  str = str.replace(new RegExp("[^0-9]+", "g"), "");
  if (str.length === 11) {
    str = str.toString().replace(/(\d{3})\d*(\d{2})/, "$1******$2");
  } else {
    str = str.toString().replace(/(\d{3})\d*(\d{2})/, "$1******$2");
  }
  return str;
});
